﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>购物车</title>


	<script src="../js/plugins/shopcar/js/jquery-2.1.4.min.js"></script>
	<script src="../js/plugins/shopcar/js/shopping.js"></script>
	<link rel="stylesheet" href="../js/plugins/shopcar/css/base.css">
	<link rel="stylesheet" href="../js/plugins/shopcar/css/module.css">
	<script src="../js/common.js"></script>
	<script src="../js/plugins/jrender/jrender.min.js"></script>
	<script>
        $(function () {


            var cdata;
            //加入购物车
            $.get("/shop/car",function (data) {
                cdata=data;
                console.log(data);
                $("#car").renderValues(data)
				var html=0;
				$.each(data.list,function (index, value) {
                    console.log(value.integral)
					html+=value.integral;
                })
                console.log(html);
                $("#AllTotal").html(html)

				//删除商品
                $(".deleteBtn").click(function () {
                    var id=$(".id").data('id')
                    console.log(id);
                     $.ajax({
                         type: "Delete",
                         url: "/shop/"+id+"/buycommodity",
                         success: function(msg){
                             alert("删除成功");
                             window.location.reload()

                         }
                     });



                })



            })
			//全部结算
            jQuery.ajaxSettings.traditional = true;
            $(".buyBtn").click(function () {
               /* console.log(cdata.list);*/
                var ids = [];

                $.each(cdata.list,function (index, value) {
                   var id=value.id
                    ids.push(id)
                })
                console.log(ids);

                 var totalPrice= $("#AllTotal").html()
                 console.log(totalPrice);
                 $.ajax({
                     type: "PUT",
                     url: "/shop/"+totalPrice+"/buycommodity/"+[ids],
                     success: /*function(msg){
                         alert("付款成功");
                         window.location.href ="/mine/profiles.html"

                     }*/
                         $(document).dialog({
                             type : 'confirm',
                             content: '付款成功',
                             buttonClassConfirm: 'custom-confirm',
                             buttonClassCancel: 'custom-cancel',
                             buttons: [
                                 {
                                     callback: function() {
                                         window.location.href ="/mine/profiles.html"
                                     }
                                 }
                             ]
                         })
                 });

            })






        })
	</script>
	<link rel="stylesheet" href="../js/plugins/dialog2/dialog.css">
	<script src="../js/plugins/dialog2/dialog.min.js"></script>


</head>
<body>

<!--头部开始-->
<div class="header">
	<h1>购物车</h1>
	<a href="/mine/mallFrontPage.html" class="back"><span></span></a>
	<a href="#" class=""></a>
</div>
<!--头部结束-->
<div class="shopping">
	
	<div class="shop-group-item" id="car">
		<div class="shop-name">
			<input type="checkbox" class="check goods-check shopCheck">
			<h4><a href="#">购物车商品列单</a></h4>
		</div>
		<ul>
			<li >

				<div render-loop="list">
				<div class="shop-info">
					<input type="checkbox" class="check goods-check goodsCheck">
					<div class="shop-info-img"><a href="#"><img render-src="list.coverUrl"/></a></div>
					<div class="shop-info-text">
						<h4 render-html="list.title"></h4>
						<div class="shop-brief"><span>重量:3g</span><span>颜色:标配版</span><span>版本:2.0</span></div>
						<div class="shop-price">
							<div class="shop-pices">￥<b class="price" render-html="list.integral"></b></div>
							<div class="shop-arithmetic">
								<button   class="minus" render-data-count="list.integral">-</button>
								<span class="num" >1</span>
								<button  class="plus" render-data-count="list.integral">+</button>
							</div>
                            <div class="delete">
                                <input type="hidden" class="id" render-attr="data-id=list.id">
                                <input type="button" value="删除"  class="deleteBtn"></div>

						</div>
					</div>
				</div>
				</div>

			</li>



		</ul>
		<!--<div class="shopPrice">本店总计：￥<span class="shop-total-amount ShopTotal">0.00</span></div>-->
	<!--</div>-->
	</div>
</div>
<div class="payment-bar">
	<!--<div class="all-checkbox"><input type="checkbox" class="check goods-check" id="AllCheck">全选</div>-->
	<div class="shop-total">
		<strong>总价：<i class="total" id="AllTotal">0</i></strong>
	</div>
	<a href="#" class="settlement buyBtn">结算</a>
</div>

</body>
</html>

